package ru.tennisworld.match.repositories.base;

import jakarta.persistence.QueryHint;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;
import org.springframework.data.repository.NoRepositoryBean;
import ru.tennisworld.match.entities.base.BaseReferenceEntity;

@NoRepositoryBean
public interface BaseReferenceEntityRepository<T extends BaseReferenceEntity>
        extends JpaRepository<T, Long>, JpaSpecificationExecutor<T> {

    @Query("select t from #{#entityName} t where upper(t.code) = upper(?1) ")
    @QueryHints({
            @QueryHint(name = "org.hibernate.cacheable", value = "true")
    })
    T getReferenceByCode(String code);

}
